package com.atguigu.customer.service.impl;

import com.atguigu.customer.bean.Customer;
import com.atguigu.customer.mapper.CustomerMapper;
import com.atguigu.customer.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("customer1")
@DS("dga")
public class CustomerServiceImpl  extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {
    @Override
    public Customer getCustomerById(Integer id) {
        Customer customer = customerMapper.selectById(id);
        // Customer customer = customerMapper.getCustomerById(id);
        return customer;
    }

    @Autowired
    CustomerMapper customerMapper;
    @Override
    public void saveCustomer(Customer customer) {
        // 把Customer保存到数据库表中

       // customerMapper.saveCustomer(customer);
        customerMapper.insert(customer);

        System.out.println("save customer to database ::"+customer);

    }

    @Override
    public List<Customer> getCustomerByName(String name) {
        List<Customer> customerList  = customerMapper.selectList(new QueryWrapper<Customer>().like(name != null, "name", name));
       // List<Customer> customerList = customerMapper.getCustomerByName(name);
        return customerList;
    }
}
